Repository navigation
Conversation
## summary - Move `EXCLUDED`, `COMMANDS`, and `command_help` into `opendirector.agent.command_help` and re-export them from `opendirector.agent.tools` so `opendirector.cli` no longer pulls in application and storage modules at startup. - Build CLI option signatures in `register_command` from `payload.model_fields` instead of calling `model_json_schema()` and synthesizing validated `command_help` examples for all registered commands during module import; render `--help` epilogs and field schemas on demand while preserving identical help, `--help-field`, and `capabilities` output. - Defer `DELIVERY_GUIDANCE` import and `httpx.Client` construction on `cli.Client` until an HTTP request or succeeded `job.get` query needs them, avoiding unused client setup during live Agent socket calls. - Add `test_cli_defers_command_schemas_and_http_client_until_used` in `tests/test_cli.py` covering cold-import schema counts, module isolation, live socket HTTP avoidance, targeted flag parsing, and lazy `--help` / `--help-field` rendering. ## validation - `.venv/bin/python -m pytest tests/test_cli.py tests/test_cli_discovery.py tests/test_asset_download_cli.py tests/test_canvas_text_cli.py tests/test_canvas_text_cli_http.py tests/test_windows_powershell.py tests/test_agent_metadata.py tests/test_agent_artifacts.py tests/test_agent_gateway.py tests/test_agent_job_lineage.py tests/test_agent_timing.py tests/test_video_link_import.py tests/test_timeline_packages.py tests/test_h3_keyframes.py tests/test_capability_acceptance.py --basetemp=/tmp/od-pytest -q` - `.venv/bin/python -m pytest tests/test_native_runtime.py tests/test_pi_runtime.py tests/test_antigravity_runtime.py tests/test_deepseek_runtime.py tests/test_jiuwenswarm_runtime.py tests/test_creation_contracts.py tests/test_layer_boundary.py tests/test_bench_turn_timing.py tests/test_launcher.py tests/test_installation.py --basetemp=/tmp/od-pytest2 -q` - `npm test` - `.venv/bin/lint-imports` - `.venv/bin/python scripts/generate_contracts.py --check` - `npm run check:i18n` - `npm run build` Refs: ThinkFlowLab#632
f17ea2a to
56584fe
Compare
david6666666
left a comment
There was a problem hiding this comment.
Dot,代表 @david6666666。93/100,本条为非表决 COMMENT。
拆分方向对:我把移前移后的 command_help() 做了逐字对比,主体完全相同。普通命令不再提前构建 schema;显式字段仍走原来的 schema 解析分支,--help-field 和 epilog 按需生成,Agent socket 路径不需要为生成 wait 命令先打开 HTTP client。没有可执行的阻塞发现。
作者附的 5 轮本地交错 A/B,15 条 CLI 命令中位数 7.18 → 3.18 s(2.26×);这是 macOS 本地 Unix socket,不是 LLM/provider 的端到端加速。我核对了原始回执及同 SHA Release checks,Release、CodeQL 和 DSH 均通过;未独立重跑基准或验证 Windows PowerShell。
范围 3/3、正确性 3/3、验证 2/3、主张证据 3/3、简洁度 3/3。Base d083cbc129862d62fc5ddf3d3e265cc6d5db3c2a / head 56584feb6de64f441830f9355bb00fba66f52a2b。当前正式 reviewer 是仓库请求的人员;我未投票或合入。
## summary - Merge `origin/main` (`8cdf67ec`) into `perf/cli-lazy-command-schema`, keeping `opendirector.agent.command_help` separated from `opendirector.agent.tools` alongside `CLI_DISCOVERY_RULE`, preserving `ThinkFlowLab#681`'s `job.status` delivery lookup in `Client.query`, and retaining `ThinkFlowLab#662`'s `receipt show` and `command_conflict` CLI coverage together with `test_cli_defers_command_schemas_and_http_client_until_used`. Refs: ThinkFlowLab#632
|
Merged
|
david6666666
left a comment
There was a problem hiding this comment.
当前证据暂定 93/100,非批准分(范围 3、正确性 3、验证 2、主张证据 3、简洁度 3)。复核合并后的四个文件,CLI schema、help 和 HTTP client 的按需逻辑仍在,现有 job.status / receipt show 合约也留住了。之前的 7.18→3.18s 只代表同机器 Unix socket 交错抽样,没有在这版重跑。
当前 Release 唯一失败的测试是 Python shard 清单缺 Ark、test_wait_outcome.py、test_trace_job_queries.py,三项在这版所基于的 main 同样缺,不是 schema 回归。当前 main 已补了一项;建议集中补齐剩余两项,不要为落后一个提交机械 rebase。未独立运行 CLI。Dot,代表 @david6666666,非表决复审。
Summary
EXCLUDED,COMMANDS, andcommand_helpintoopendirector.agent.command_help(re-exported byopendirector.agent.tools) so importingopendirector.clino longer pulls inopendirector.agent.toolsand its application/storage module graph on every CLI invocation (while preserving#681'sjob.status-based delivery lookup inClient.query).register_commandfrompayload.model_fieldsinstead of callingmodel_json_schema()twice for all 47 model-registered commands (47 × 2 = 94schema builds) and runningcommand_help()(recursive example synthesis, Pydanticmodel_validate, andjson.dumps) for all 44COMMANDSentries at module import time. AttachLazyEpilogCommand(TyperCommandsubclass) and on-demand field-schema lookup so--help,--help-field, andcapabilitiesoutputs remain byte-for-byte identical while ordinary CLI calls only inspect the invoked command.cli.Client.http(httpx.Client) on first HTTP access (preservingclient.http = ...assignment and cleanup on close) and formatnextwait URLs viahttpx.URL, avoiding unused HTTP/TLS client initialization during live Agent socket calls.test_cli_defers_command_schemas_and_http_client_until_usedintests/test_cli.pyasserting zeroBaseModel.model_json_schemacalls onimport opendirector.cliandproject show --summary, absence ofopendirector.agent.tools/opendirector.application.creation_canvason cold import, zerohttpx.Clientconstruction on live socket commands, single-payload schema lookup ongeneration submit, and intact on-demand--help/--help-fieldoutput.Linked issue
Refs #632 (supplementary local CLI startup optimization aligned with the Agent efficiency workstream; does not close the weekly roadmap issue).
Fixes #NorRefs #Nis included, or no issue appliesLabels
Requested:
type:refactor,area:performance,area:agent(fork PR without label write permission)Test plan
7ca371415820f4eaee5a46fd66bdb91470bc34ebmerged withorigin/main8cdf67ec32d1ba5da8c3eef63d013267e714e9b7, updating previously reviewed56584feb6de64f441830f9355bb00fba66f52a2b):.venv/bin/python -m pre_commit run --from-ref origin/main --to-ref HEAD(all hooks passed)PYTHONPATH=<origin/main-worktree>/packages/core/src .venv/bin/python -m pytest tests/test_cli.py -k test_cli_defers_command_schemas_and_http_client_until_used -q(verified to fail on based083cbc129862d62fc5ddf3d3e265cc6d5db3c2a/8cdf67ec32d1ba5da8c3eef63d013267e714e9b7withAssertionError: 94 eagermodel_json_schemacalls duringimport opendirector.cli, and pass on7ca371415820f4eaee5a46fd66bdb91470bc34eb)PYTHONPATH=packages/core/src:apps/api/src .venv/bin/python -m pytest tests/test_cli.py tests/test_cli_discovery.py tests/test_agent_gateway.py tests/test_command_version_contract.py tests/test_wait_outcome.py tests/test_a2_repros.py -q(210 passed)PYTHONPATH=packages/core/src:apps/api/src .venv/bin/python -m pytest tests/test_native_runtime.py tests/test_pi_runtime.py tests/test_antigravity_runtime.py tests/test_deepseek_runtime.py tests/test_jiuwenswarm_runtime.py tests/test_structure_reference.py -k "not test_rejects_removed_runtime_and_invalid_selection_before_acceptance" -q(98 passed, 7 skippedin thenode_modules-less--setup skipworktree;test_rejects_removed_runtime_and_invalid_selection_before_acceptancechecksSOURCE_ROOT/node_modules/.bin/opencode).venv/bin/lint-imports(4 kept, 0 broken).venv/bin/python scripts/generate_contracts.py --check(Creation contracts verified)docs/development/lessons.md:tests/test_ci_layers.py::test_repo_python_shards_manifest_covers_every_test_module_oncecurrently fails on upstreamorigin/main8cdf67ec32d1ba5da8c3eef63d013267e714e9b7because#676(tracked in#695) and#681did not registertests/test_ark_availability.py,tests/test_trace_job_queries.py, andtests/test_wait_outcome.pyinscripts/ci/python_shards.json(this PR adds no new test module).Release checks,CodeQL,DSH plugin checks):Release checks(static,python3-shard matrix [core,agent-cli,media],python-native,frontend,browser[isolated,voice,assistant],checks),CodeQL, andDSH plugin checkson7ca371415820f4eaee5a46fd66bdb91470bc34eb(all passed previously on56584feb6de64f441830f9355bb00fba66f52a2b).8cdf67ec32d1ba5da8c3eef63d013267e714e9b77ca371415820f4eaee5a46fd66bdb91470bc34eb83/100(Scope and intent 3/3,Correctness and safety 3/3,Validation 2/3,Claim evidence 2/3,Simplicity 3/3; previously93/100on56584feb6de64f441830f9355bb00fba66f52a2b)Release checks,CodeQL,DSH plugin checks) and Windows PowerShell CLI runtime checks have not yet finished on merged tip7ca371415820f4eaee5a46fd66bdb91470bc34eb(and upstreamorigin/main8cdf67eccurrently has the shard-manifest baseline failure noted above pending#695/#681follow-up); performance measurements below reflect a single-machine local Unix-socket CLI benchmark rather than end-to-end provider turns.Evidence that it works
--helpepilog synthesis, andhttpx.Clientinstantiation insideopendirector.cli/opendirector.agent.command_help. No UI layout, user-facing text, or CLI response/help output changed: the root CLI, all top-level command groups, and allregistered_commands()leaf subcommands (NO_COLOR=1andFORCE_COLOR=1--helpoutputs), pluscapabilities,capabilities --compact, andregistered_commands()were compared byte-for-byte against base with zero differences.d083cbc129862d62fc5ddf3d3e265cc6d5db3c2avs head56584feb6de64f441830f9355bb00fba66f52a2bafter 1 warmup pair; each round spawns 15 sequentialpython -m opendirector.clisubprocesses over a livecli_transportUnix-domain socket against an isolatedLocalProjectsstore:project show --summary,model list --kind video,asset write-text, 3×canvas add-material, 3×generation-spec create, 3×canvas show, 2×query object.get,project show --summary):d083cbc1(5 rounds)56584feb(5 rounds)7176.6, 7250.8, 7211.4, 6942.0, 6664.03083.5, 3203.0, 3067.6, 3176.1, 3285.77176.6 ms → 3176.1 ms−4000.5 ms,−55.7%)cli_transportreportedtiming.spawnsum across 15 calls (ms)6120.0, 6130.0, 6072.0, 5921.0, 5672.02257.0, 2349.0, 2244.0, 2309.0, 2378.06072.0 ms → 2309.0 ms−3763.0 ms,−62.0%)project show --summaryCLI call wall time (ms)464.7, 514.0, 456.9, 437.5, 437.0195.3, 205.8, 222.9, 254.9, 244.4456.9 ms → 222.9 ms−234.0 ms,−51.2%)BaseModel.model_json_schemacalls duringimport opendirector.cli94094 → 0−94calls per process(Scope limitation: numbers above reflect a deterministic single-machine synthetic CLI sequence over local Unix sockets and do not claim end-to-end LLM/provider turn improvements or replace
#632B1 benchmarks.)Raw 5-round interleaved A/B JSON receipt & benchmark command
Reproduce with two worktrees checked out at
d083cbc129862d62fc5ddf3d3e265cc6d5db3c2a(BASE_WORKTREE) and56584feb6de64f441830f9355bb00fba66f52a2b(HEAD_WORKTREE):Raw JSON output:
{ "rounds": [ { "round": 1, "base": { "calls": 15, "sequenceWallMs": 7176.6, "transportSpawnSumMs": 6120.0, "firstSummaryWallMs": 427.9, "lastSummaryWallMs": 464.7 }, "head": { "calls": 15, "sequenceWallMs": 3083.5, "transportSpawnSumMs": 2257.0, "firstSummaryWallMs": 194.4, "lastSummaryWallMs": 195.3 } }, { "round": 2, "base": { "calls": 15, "sequenceWallMs": 7250.8, "transportSpawnSumMs": 6130.0, "firstSummaryWallMs": 448.3, "lastSummaryWallMs": 514.0 }, "head": { "calls": 15, "sequenceWallMs": 3203.0, "transportSpawnSumMs": 2349.0, "firstSummaryWallMs": 216.1, "lastSummaryWallMs": 205.8 } }, { "round": 3, "base": { "calls": 15, "sequenceWallMs": 7211.4, "transportSpawnSumMs": 6072.0, "firstSummaryWallMs": 515.2, "lastSummaryWallMs": 456.9 }, "head": { "calls": 15, "sequenceWallMs": 3067.6, "transportSpawnSumMs": 2244.0, "firstSummaryWallMs": 199.2, "lastSummaryWallMs": 222.9 } }, { "round": 4, "base": { "calls": 15, "sequenceWallMs": 6942.0, "transportSpawnSumMs": 5921.0, "firstSummaryWallMs": 459.2, "lastSummaryWallMs": 437.5 }, "head": { "calls": 15, "sequenceWallMs": 3176.1, "transportSpawnSumMs": 2309.0, "firstSummaryWallMs": 197.8, "lastSummaryWallMs": 254.9 } }, { "round": 5, "base": { "calls": 15, "sequenceWallMs": 6664.0, "transportSpawnSumMs": 5672.0, "firstSummaryWallMs": 433.4, "lastSummaryWallMs": 437.0 }, "head": { "calls": 15, "sequenceWallMs": 3285.7, "transportSpawnSumMs": 2378.0, "firstSummaryWallMs": 194.1, "lastSummaryWallMs": 244.4 } } ], "medians": { "sequence15CallsWallMs": { "base": 7176.6, "head": 3176.1, "savedMs": 4000.5, "speedup": 2.26 }, "transportSpawnSum15CallsMs": { "base": 6072.0, "head": 2309.0, "savedMs": 3763.0, "speedup": 2.63 }, "singleSummaryCallWallMs": { "base": 456.9, "head": 222.9, "savedMs": 234.0, "speedup": 2.05 } } }Provider verification
No live external model or media provider calls were made. All tests and benchmarks ran locally against
LocalProjects, FastAPITestClient, and localcli_transport/ mocked HTTP transports.Bilingual UI
No user-visible UI strings, error messages, or localized catalogs changed (
npm run check:i18npassed with 0 problems).